#ifndef GAMEPANEL_H
#define GAMEPANEL_H
#include <QMainWindow>
#include <QPainter>
#include<QMap>
#include <QTimer>
#include"card.h"
#include"cards.h"
#include "countdown.h"
#include<cardpanel.h>
#include <QLabel>
#include"gamecontrol.h"
#include"animaltionwindow.h"
#include<QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class GamePanel; }
QT_END_NAMESPACE

class GamePanel : public QMainWindow
{
    Q_OBJECT

public:
    GamePanel(QWidget *parent = nullptr);
    ~GamePanel();
    enum AnimaltionType{ShunZi,LianDui,Plane,JokerBomb,Bomb,Bet};

    void gameControlInit();
    void updatePlayerScore();
    void initCardMap();
    void cropimage(QPixmap& pix , int x , int y,Card& c);
    void initButtonsGroup();
    void initPlayerContest();
    void initGameScene();
    void gameStatusPrecess(GameControl::GameStatus statu);
    void startDispatchCard();
    void onDispatchCard();
    void cardMoveStep(Player *player,int curPos);
    void disposeCard(Player *player,const Cards &cards);
    void updataPlayerCards(Player *player);
    void onPlayerStatusChanged(Player *player,GameControl::PlayerStatus status);
    void onGrabLordBet(Player *player,int bet , bool flag);
    void showAnimaltion(AnimaltionType type , int bet = 0);
    void DisposePlayHand(Player *player,Cards &cards);
    void hidePlayerDropCards(Player *player);
    QPixmap loadRoleImage(Player::Sex sex,Player::Direction direct,Player::Role role);
    void onCardSelected(Qt::MouseButton button);
    void onUserPlayHand();
    void onUserPass();
    void showEndingScorePanel();
    void initCountDown();
private:
    Ui::GamePanel *ui;
    enum CardAlign{Horizontal,Vertical};
    struct PlayerContext
    {
        QRect cardRect;
        QRect playHandRect;
        CardAlign align;
        bool isFrontSize;
        QLabel *info;
        QLabel *roleimg;
        Cards lastCards;
    };

    QPixmap m_pixmap;
    GameControl *m_gamecontrol;
    QVector<Player*> m_playerList;
    QMap<Card,CardPanel*> m_cardmap;
    QSize m_cardSize;
    QPixmap m_cardbackimage;
    QMap<Player*,PlayerContext> m_contextMap;
    CardPanel *m_baseCard;
    CardPanel *m_moveCard;
    QVector<CardPanel*> m_last3Card;
    QPoint m_baseCardPos;
    GameControl::GameStatus m_status;
    QTimer *m_timer;
    Animaltionwindow *m_animaltion;
    CardPanel *m_curCardPanel;
    QSet<CardPanel*> m_selectCards;
    QRect m_cardRect;
    QHash<CardPanel*,QRect> m_usercard;
    CountDown *m_countDown;

    // QWidget interface
protected:
    virtual void paintEvent(QPaintEvent *event) override;

    // QWidget interface
protected:
    virtual void mouseMoveEvent(QMouseEvent *event) override;
};




#endif // GAMEPANEL_H
